package Offer;

import java.util.ArrayList;
import java.util.List;

/**
 *  和为s的连续正数序列
 * @author 是阿秋啊
 * @date 2022/08/17 21:14
 **/
public class Num57II {
    public static int[][] findContinuousSequence(int target) {
        int i = 1, j = 2,s = 3;
        List<int[]> ret = new ArrayList<>();
        while(i < j) {
            if(s == target) {
                int[] tmp = new int[j - i + 1];
                for(int k = i; k <= j;k++){
                    tmp[k - i] = k;
                }
                ret.add(tmp);
                s-=i;
                i++;
            }
            if(s < target) {
                j++;
                s+=j;
            }
            if(s > target) {
                s-=i;
                i++;
            }
        }
        return ret.toArray(new int[0][]);
    }
}